<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function sendAjax(url) {
            return new Promise((resolve, reject) => {
                //1、创建请求对象
                const xhr = new XMLHttpRequest();

                //2、初始化请求
                xhr.open("get", url);

                //3、发送请求
                xhr.send(null);

                //4、响应回调事件
                xhr.onreadystatechange = function () {
                    if (xhr.readyState === 4) {  //发送成功
                        if (xhr.status >= 200 && xhr.status < 300) { //响应成功
                            resolve(xhr.responseText);
                        }
                        else {
                            reject(xhr.status);
                        }
                    }
                }
            });
        }

        async function main() {
            try {
                let result = await sendAjax("http://127.0.0.1:5500/data.json");
                console.log(result);
            }
            catch (err) {
                console.log(err);
            }
        }

        main();
    </script>
</body>

</html>